<?php
ob_start();
session_start();
$id_member = $_SESSION["id_member"];
?>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
        <link rel="stylesheet" href="../css/style.css"/>
<!--         <script type="text/javascript" src="../js/jquery/jquery.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.validationEngine.js"></script>
<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css" />-->
        <script type="text/javascript" src="../js/jquery/jquery-latest.min.js"></script>
    </head>
    <body>
        <div align="center">

            <?php
            include_once "../connect.php";

            $cn_id = $_GET["cn_id"];


            if (!empty($cn_id)) {

                $sql = "SELECT * FROM comname LEFT JOIN depart ON comname.de_id = depart.id
                                                         LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                         LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                         LEFT JOIN employee ON comname.emp_id = employee.emp_id   
                                                         LEFT  JOIN product_detail ON comname.cn_number =  product_detail.pd_id                                 
                                                         WHERE comname.cn_id = '$cn_id' 
                                            ";
                $rs = mysql_query($sql);

                if ($rs) {

                    $r = mysql_fetch_array($rs);
                } else {

                    echo mysql_error();
                }
            }
            ?>

            <script type="text/javascript">

                $(document).ready(function() {

                    $("#emp_id").change(function() {
                        $.ajax({
                            url: "returnAddListCom.php",
                            type: "POST",
                            data: 'semp_id=' + $("#emp_id").val()
                        })
                                .success(function(result) {

                            var obj = jQuery.parseJSON(result);

                            if (obj == '')
                            {
//                            $('input[type=text]').val('');
                                alert("ไม่พบพนักงานในระบบ");
                            }
                            else
                            {
                                $.each(obj, function(key, inval) {

                                    $("#emp_id").val(inval["emp_id"]);
                                    $("#cn_department").val(inval["departname"]);
                                    $("#c_nameUser").val(inval["emp_nameEng"]);

                                });
                            }

                        });

                    });
                });
            </script>
            <script type="text/javascript">
                $(document).ready(function() {

                    $("#cn_number").change(function() {
                        $.ajax({
                            url: "returnAddListComName.php",
                            type: "POST",
                            data: 'scn_number=' + $("#cn_number").val()
                        })
                                .success(function(result) {

                            var obj = jQuery.parseJSON(result);

                            if (obj == '')
                            {

                            }
                            else
                            {
                                $.each(obj, function(key, inval) {

                                    $("#cnNumber").val(inval["cn_number"]);
                                    if (eval("document.frmMain.cnNumber.value") != "") {
                                        alert("หมายเลขเครื่องคอมพิวเตอร์ มีในระบบแล้ว");
                                        eval("document.frmMain.cnNumber.focus();")
                                        return false;
                                    }

                                });


                            }
                        });
                    });
                });
            </script>
            <script language="javascript">
                function CheckValidate()
                {
                  

                    if (eval("document.frmMain.cn_comeName.value") == "") {
                        alert("กรุณากรอกช่อง ชื่อเครื่อง");
                        eval("document.frmMain.cn_comeName.focus();")
                        return false;
                    }

                    if (eval("document.frmMain.emp_id.value") == "") {
                        alert("กรุณาเลือกช่อง รหัสพนักงาน");
                        eval("document.frmMain.emp_id.focus();")
                        return false;
                    }

                    if (eval("document.frmMain.cn_ip.value") == "") {
                        alert("กรุณากรอกช่อง IP Adress");
                        eval("document.frmMain.cn_ip.focus();")
                        return false;
                    }

                    if (eval("document.frmMain.c_mb.value") == "") {
                        alert("กรุณากรอกช่อง M/B Brand/Model");
                        eval("document.frmMain.c_mb.focus();")
                        return false;
                    }

                    if (eval("document.frmMain.c_vga.value") == "") {
                        alert("กรุณากรอกช่อง VGA Brand/Model");
                        eval("document.frmMain.c_vga.focus();")
                        return false;
                    }

                    if (eval("document.frmMain.c_cpu.value") == "") {
                        alert("กรุณากรอกช่อง CPU Brand/Model");
                        eval("document.frmMain.c_cpu.focus();")
                        return false;
                    }


                    if (eval("document.frmMain.c_ram.value") == "") {
                        alert("กรุณากรอกช่อง RAM Brand/Model");
                        eval("document.frmMain.c_ram.focus();")
                        return false;
                    }

                   

                    if (eval("document.frmMain.c_hdd.value") == "") {
                        alert("กรุณากรอกช่อง HDD Brand/Vol/Size");
                        eval("document.frmMain.c_hdd.focus();")
                        return false;
                    }

                    

                    if (eval("document.frmMain.c_sound.value") == "") {
                        alert("กรุณากรอกช่อง  Sound Brand/Model");
                        eval("document.frmMain.c_sound.focus();")
                        return false;
                    }

                    

                    if (eval("document.frmMain.c_cdRom.value") == "") {
                        alert("กรุณากรอกช่อง CD/ROM Brand/Model");
                        eval("document.frmMain.c_cdRom.focus();")
                        return false;
                    }
                 

                    if (eval("document.frmMain.c_lan.value") == "") {
                        alert("กรุณากรอกช่อง Lan Card Brand/Model");
                        eval("document.frmMain.c_lan.focus();")
                        return false;
                    }



                    if (eval("document.frmMain.c_nameUser.value") == "") {
                        alert("กรุณากรอกช่อง User");
                        eval("document.frmMain.c_nameUser.focus();")
                        return false;
                    }


                    if (eval("document.frmMain.cn_department.value") == "") {
                        alert("กรุณากรอกช่อง แผนกฝ่าย");
                        eval("document.frmMain.cn_department.focus();")
                        return false;
                    }

                    if (eval("document.frmMain.cnNumber.value") != "") {
                        $(document).ready(function() {

                            $("#cn_number").change(function() {
                                $.ajax({
                                    url: "returnAddListComName.php",
                                    type: "POST",
                                    data: 'scn_number=' + $("#cn_number").val()
                                })
                                        .success(function(result) {

                                    var obj = jQuery.parseJSON(result);

                                    if (obj == '')
                                    {

                                    }
                                    else
                                    {
                                        $.each(obj, function(key, inval) {

                                            $("#cnNumber").val(inval["cn_number"]);
                                        });

                                    }
                                });
                            });
                        });
                    }

                }
            </script>
            <fieldset>
                <legend class="nameTitle">แก้ไขทะเบียนประวัติคอมพิวเตอร์</legend>
                <form
                    method="POST"
                    action="updateListCom_save.php"
                    enctype="multipart/form-data"
                    name ="frmMain" id="frmMain" OnSubmit="return CheckValidate();" />
                <table class="inputcontenttable"><br />

                    <tr align="left">
                        <td align="left">รหัสเครื่อง</td> 
                        <td> 
                            <select name="cn_number" id="cn_number">	
                                <option value="<?= $r[cn_number] ?>"><?= $r[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '4' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		

                                    <?
                                }
                                ?>
                            </select>
                        </td>     
                        <td></td>
                        <td>ชื่อเครื่อง</td>                       
                        <td><input id="cn_comeName" name="cn_comeName" type="text" value="<?= $r[cn_comeName] ?>"/></td>
                    </tr>
                    <tr valign="top" >
                        <td>รหัสพนักงาน</td>
                        <td><input id="emp_id" name="emp_id" type="text"  value="<?= $r[6] ?>"/></td>      
                        <td width="50px"></td>
                        <td>IP Adress</td>
                        <td><input id="cn_ip" name="cn_ip" type="text"  value="<?= $r[cn_ip] ?>"/></td>                          
                    </tr>
                    <tr valign="top">
                    </tr>
                    <tr valign="top">
                        <td>M/B Brand/Model</td>
                        <td><input id="c_mb" name="c_mb" type="text" value="<?= $r[c_mb] ?>"/></td>   
                        <td width="50px"></td>
                        <td>VGA Brand/Model</td>
                        <td><input id="c_vga"  name="c_vga" type="text" value="<?= $r[c_vga] ?>"/></td>                          
                    </tr> 
                    <tr valign="top" >
                        <td>CPU Brand/Model</td>
                        <td><input id="c_cpu"  name="c_cpu" type="text" value="<?= $r[c_cpu] ?>" /></td>    
                        <td width="50px"></td>
                        <td>FDD Brand/Model</td>
                        <td><input  name="c_fdd" type="text" value="<?= $r[c_fdd] ?>" /></td>                          
                    </tr>
                    <tr valign="top" >
                        <td>RAM Brand/Vol/Size</td>
                        <td><input id="c_ram"  name="c_ram" type="text" value="<?= $r[c_ram] ?>" /></td>        
                        <td width="50px"></td>
                        <td>K/B Brand/Model</td>
                        <td> 
                            <select name="c_keyboard" id="c_keyboard">	
                                <?php
                                include_once "../connect.php";
                                if (!empty($cn_id)) {

                                    $sql = "SELECT * FROM comname LEFT JOIN depart ON comname.de_id = depart.id
                                                         LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                         LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                         LEFT JOIN employee ON comname.emp_id = employee.emp_id   
                                                         LEFT  JOIN product_detail ON computer.c_keyboard =  product_detail.pd_id                                        
                                                         WHERE comname.cn_id = '$cn_id' 
                                            ";
                                    $rsk = mysql_query($sql);
                                    if ($rsk) {
                                        $rk = mysql_fetch_array($rsk);
                                    } else {
                                        echo mysql_error();
                                    }
                                }
                                ?>
                                <option value="<?= $rk[c_keyboard] ?>"><?= $rk[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '1' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		

                                    <?
                                }
                                ?>
                            </select>
                        </td>                       
                    </tr>
                    <tr valign="top" >
                        <td>HDD Brand/Vol/Size</td>
                        <td><input  name="c_hdd" type="text" value="<?= $r[c_hdd] ?>"/></td>  
                        <td width="50px"></td>
                        <td>Mouse Brand/Model</td>
                        <td> 
                            <select name="c_mouse" id="c_mouse">
                                <?php
                                include_once "../connect.php";
                                if (!empty($cn_id)) {

                                    $sql = "SELECT * FROM comname LEFT JOIN depart ON comname.de_id = depart.id
                                                         LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                         LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                         LEFT JOIN employee ON comname.emp_id = employee.emp_id   
                                                         LEFT  JOIN product_detail ON computer.c_mouse =  product_detail.pd_id                                        
                                                         WHERE comname.cn_id = '$cn_id' 
                                            ";
                                    $rsm = mysql_query($sql);
                                    if ($rsm) {
                                        $rm = mysql_fetch_array($rsm);
                                    } else {
                                        echo mysql_error();
                                    }
                                }
                                ?>
                                <option value="<?= $rm[c_mouse] ?>"><?= $rm[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '2' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"><?= $objResuut["pd_code"]; ?>  <?= $objResuut["pd_name"]; ?></option>		

                                    <?
                                }
                                ?>
                            </select>
                        </td>
                        <!--<td><input id="c_mouse"  name="c_mouse" type="text" value="<?= $r[c_mouse] ?>" readonly/></td>-->     
                    </tr>
                    <tr valign="top" >
                        <td>Sound Brand/Model</td>
                        <td><input id="c_sound"  name="c_sound" type="text" value="<?= $r[c_sound] ?>" /></td>    
                        <td width="50px"></td>
                        <td>Monitor Brand/Model</td>
                        <td> 
                            <select name="c_monitor" id="c_monitor">	
                                <?php
                                include_once "../connect.php";
                                if (!empty($cn_id)) {

                                    $sql = "SELECT * FROM comname LEFT JOIN depart ON comname.de_id = depart.id
                                                         LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                         LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                         LEFT JOIN employee ON comname.emp_id = employee.emp_id   
                                                         LEFT  JOIN product_detail ON computer.c_monitor =  product_detail.pd_id                                        
                                                         WHERE comname.cn_id = '$cn_id' 
                                            ";
                                    $rsmo = mysql_query($sql);
                                    if ($rsmo) {
                                        $rmo = mysql_fetch_array($rsmo);
                                    } else {
                                        echo mysql_error();
                                    }
                                }
                                ?>
                                <option value="<?= $rmo[c_monitor] ?>"><?= $rmo[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '3' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top" >
                        <td>CD/ROM Brand/Model</td>
                        <td><input id="c_cdRom"  name="c_cdRom" type="text" value="<?= $r[c_cdRom] ?>" /></td>  
                        <td width="50px"></td>
                        <td>Speaker Brand</td>
                        <td><input  id="c_speaker" name="c_speaker" type="text" value="<?= $r[c_speaker] ?>" /></td>                          
                    </tr>
                    <tr valign="top" >
                        <td>Lan Card Brand/Model</td>
                        <td><input id="c_lan" name="c_lan" type="text" value="<?= $r[c_lan] ?>" /></td>    
                        <td width="50px"></td>
                        <td>Notice</td>
                        <td><input  name="c_notic" type="text" value="<?= $r[c_notic] ?>"/></td>                          
                    </tr>
                    <tr valign="top" >
                        <td colspan="5" align="center">Other Device</td>                           
                    </tr>
                    <tr valign="top" >
                         <?php
                                include_once "../connect.php";
                                if (!empty($cn_id)) {

                                    $sql = "SELECT * FROM comname
                                                                LEFT JOIN depart ON comname.de_id = depart.id
                                                                LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                                LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                                LEFT JOIN employee ON comname.emp_id = employee.emp_id
                                                                LEFT JOIN product_detail ON comother.oth_detail = product_detail.pd_id
                                                                LEFT JOIN product ON product_detail.prd_id = product.prd_id
                                                               
                                                                WHERE comname.cn_id ='$cn_id'
                                                                AND type_id = '6'
                                            ";
                                    $rsot = mysql_query($sql);
                                    if ($rsot) {
                                        $rot = mysql_fetch_array($rsot);
                                    } else {
                                        echo mysql_error();
                                    }
                                }
                                ?>
                         <input type="hidden" name="oth_id" value="<?= $rot[oth_id] ?>"/>
                        <td>Device</td>
                        <td><input id="oth_name"  name="oth_name" type="text" value="<?= $rot[oth_name] ?>" /></td>   
                        <td width="50px"></td>
                        <td>Case</td>
                        <td> 
                            <select name="oth_detail" id="oth_detail">	                               
                                <option value="<?= $rot[oth_detail] ?>"><?= $rot[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '6' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>                                        
                    </tr>
                    <tr valign="top" >
                         <?php
                                include_once "../connect.php";
                                if (!empty($cn_id)) {

                                    $sql = "SELECT * FROM comname
                                                                LEFT JOIN depart ON comname.de_id = depart.id
                                                                LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                                LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                                LEFT JOIN employee ON comname.emp_id = employee.emp_id
                                                                LEFT JOIN product_detail ON comother.oth_detail = product_detail.pd_id
                                                                LEFT JOIN product ON product_detail.prd_id = product.prd_id
                                                                WHERE comname.cn_id ='$cn_id'
                                                                AND type_id = '5'
                                            ";
                                    $rsot = mysql_query($sql);
                                    if ($rsot) {
                                        $rot2 = mysql_fetch_array($rsot);
                                    } else {
                                        echo mysql_error();
                                    }
                                }
                                ?>
                        <input type="hidden" name="oth_id2" value="<?= $rot2[oth_id] ?>"/>
                        <td>Device</td>
                        <td><input id="oth_name"  name="oth_name2" type="text" value="<?= $rot2[oth_name] ?>" /></td>   
                        <td width="50px"></td>
                        <td>UPS</td>
                        <td> 
                            <select name="oth_detail2" id="oth_detail2">	
                                <option value="<?= $rot2[oth_detail] ?>"><?= $rot2[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '5' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>                                        
                    </tr>
                    <tr valign="top" >
                            <?php
                                include_once "../connect.php";
                                if (!empty($cn_id)) {

                                    $sql = "SELECT * FROM comname
                                                                LEFT JOIN depart ON comname.de_id = depart.id
                                                                LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                                LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                                LEFT JOIN employee ON comname.emp_id = employee.emp_id
                                                                LEFT JOIN product_detail ON comother.oth_detail = product_detail.pd_id
                                                                LEFT JOIN product ON product_detail.prd_id = product.prd_id
                                                                WHERE comname.cn_id ='$cn_id'
                                                                AND type_id = '8'
                                            ";
                                    $rsot = mysql_query($sql);
                                    if ($rsot) {
                                        $rot3 = mysql_fetch_array($rsot);
                                    } else {
                                        echo mysql_error();
                                    }
                                }
                                ?>
                        <input type="hidden" name="oth_id3" value="<?= $rot3[oth_id] ?>"/>
                        <td>Device</td>
                        <td><input id="oth_name"  name="oth_name3" type="text" value="<?= $rot3[oth_name] ?>" /></td>   
                        <td width="50px"></td>
                        <td>Printer</td>
                        <td> 
                            <select name="oth_detail3" id="oth_detail3">	                           
                                <option value="<?= $rot3[oth_detail] ?>"><?= $rot3[pd_name] ?></option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '8' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>                                        
                    </tr>
                    <tr valign="top" >
                        <td>User</td>
                        <td><input id="c_nameUser"  name="c_nameUser" type="text" value="<?= $r[emp_nameEng] ?>" readonly/></td>     
                        <td width="50px"></td>
                        <td>แผนกฝ่าย</td>
                        <td><input  id="cn_department" name="cn_department" type="text" value="<?= $r[departname] ?>" readonly /></td>                           
                    </tr>
                    <tr>
                        <td colspan="5" align="center"><input type="submit" name="Submit" value="Save" style="height: 30px; width: 120px" /></td>
                    </tr>
                </table>
                <input type="hidden" name="cn_id" value="<?= $cn_id ?>" />
                <input type="hidden" name="c_id" value="<?= $r[c_id] ?>" />                                              
                <input type="hidden" name="de_id" value="<?= $r[de_id] ?>" />
                <input name="id_member" type="hidden" value="<?= $id_member ?>"/>
                </form>
            </fieldset>
        </div>
    </body>
</html>
